package com.base.cn.platform.os.controller.course.mould;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.service.course.mould.CouMouldMaterialService;
import com.base.cn.platform.os.service.course.mould.CouMouldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Map;
/**
 * 模块素材关联Controller
 *
 * @author s.li
 * @create 2018-04-25-9:43
 */
@Controller
@RequestMapping("/admin/course/mould")
public class AdminMouldMaterialController extends AdminBaseController {
    @Autowired
    private CouMouldMaterialService couMouldMaterialService;
    @Autowired
    private CouMouldService couMouldService;
    /**
     * 初始化添加模块的素材页面
     * @param mouldId 模块ID
     * @return 操作页面
     */
    @RequestMapping("/initMouldMaterialData")
    public String initMouldMaterialData(Model model,
                                        @RequestParam("mouldId") BigDecimal mouldId){
        Map<String,Object> couMould = couMouldService.findCouMouldById(mouldId,false,false,true);
        model.addAttribute("couMould",couMould);
        return resultPage("/course/mould/save_mould_material");
    }

    /**
     * 保存模块与素材的关联
     * @param mouldId 模块ID
     * @param materialIds 素材ID串
     * @return Map<String,Object>
     */
    @RequestMapping("/saveCouMouldMaterial")
    @ResponseBody
    public Map<String,Object> saveCouMouldMaterial(@RequestParam("mouldId") BigDecimal mouldId,
                                                   @RequestParam("materialIds") String materialIds){
        return couMouldMaterialService.saveCouMouldMaterial(mouldId,materialIds);
    }

}
